home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / wired movies and sprites / watchme / application files / comapplication.c next >
Encoding:
Text File  |  2000-06-23  |  10.1 KB  |  406 lines

  1. //////////
  2. //
  3. //    File:        ComApplication.c
  4. //
  5. //    Contains:    Application-specific code for basic QuickTime movie display and control.
  6. //                This file is used for BOTH MacOS and Windows.
  7. //
  8. //    Written by:    Tim Monroe
  9. //                Based (heavily!) on the MovieShell code written by Apple DTS.
  10. //
  11. //    Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //    Change History (most recent first):
  14. //
  15. //       <13>         12/16/98    rtm        removed all QTVR API calls, so we can remove QTVR.lib from project
  16. //       <12>         07/30/98    rtm        finished changes for WatchMe
  17. //       <11>         07/23/98    rtm        begun changes for WatchMe
  18. //       <10>         10/23/97    rtm        moved InitializeQTVR to InitApplication, TerminateQTVR to StopApplication
  19. //       <9>         10/13/97    rtm        reworked HandleApplicationMenu to use menu identifiers
  20. //       <8>         09/11/97    rtm        merged MacApplication.c and WinApplication.c into ComApplication.c
  21. //       <7>         08/21/97    rtm        first file for Windows; based on MacApplication.c for Mac sample code
  22. //       <6>         06/04/97    rtm        removed call to QTVRUtils_IsQTVRMovie in InitApplicationWindowObject
  23. //       <5>         02/06/97    rtm        fixed window resizing code
  24. //       <4>         12/05/96    rtm        added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
  25. //       <3>         12/02/96    rtm        added cursor updating to DoIdle
  26. //       <2>         11/27/96    rtm        conversion to personal coding style; added preliminary QTVR support
  27. //       <1>         12/21/94    khs        first file
  28. //       
  29. //
  30. //    WatchMe is a simple QuickTime viewer framework that demonstrates how to handle absolute and relative 
  31. //    URL chasing in a QuickTime movie.
  32. //
  33. //////////
  34.  
  35. // header files
  36. #include "ComApplication.h"
  37. #include "WatchMe.h"
  38.   
  39. // global variables for Macintosh code
  40. #if TARGET_OS_MAC
  41. #endif
  42.  
  43. // global variables for Windows code
  44. #if TARGET_OS_WIN32
  45. extern HWND                ghWnd;                                    // the MDI frame window; this window has the menu bar
  46. extern int                gNumWindowsOpen;
  47. extern LPSTR            gCmdLine;
  48. #endif
  49.  
  50. long                    gMaxMilliSecToUse = 0L;
  51.  
  52.  
  53. //////////
  54. //
  55. // InitApplication
  56. // Do any application-specific initialization.
  57. //
  58. // The theStartPhase parameter determines which "phase" of application start-up is executed,
  59. // *before* the MDI frame window is created or *after*. This distinction is relevant only on
  60. // Windows, so on MacOS, you should always use kInitAppPhase_BothPhases.
  61. //
  62. //////////
  63.  
  64. void InitApplication (UInt32 theStartPhase)
  65. {
  66.     FSSpec                myFSSpec;
  67.     char                 myName[MAX_PATH];
  68. #if TARGET_OS_WIN32
  69.     char                 myTail[] = "\\Movies\\SDKWatchMe-SourceMovies\\WatchMe.mov";
  70. #endif
  71. #if TARGET_OS_MAC
  72.     char                 myTail[] = ":Movies:SDKWatchMe-SourceMovies:WatchMe.mov";
  73. #endif
  74.     char                *myVolName = NULL;
  75.     OSStatus            myErr = noErr;
  76.     
  77.     // ***do any start-up activities that should occur before the MDI frame window is created
  78.     if (theStartPhase & kInitAppPhase_BeforeCreateFrameWindow) {
  79.         
  80.     }    // end of kInitAppPhase_BeforeCreateFrameWindow
  81.  
  82.     // ***do any start-up activities that should occur after the MDI frame window is created
  83.     if (theStartPhase & kInitAppPhase_AfterCreateFrameWindow) {
  84. #if TARGET_OS_WIN32
  85.         // maximize the frame window
  86.         ShowWindow(ghWnd, SW_SHOWMAXIMIZED);
  87.  
  88.         UpdateWindow(ghWnd);
  89.         
  90.         // on Windows, open as movie documents any files specified on the command line
  91.         SendMessage(ghWnd, WM_OPENDROPPEDFILES, 0L, 0L);
  92. #endif // TARGET_OS_WIN32
  93.     
  94.         // construct the full pathname of the target movie
  95.         myName[0] = '\0';
  96.         myVolName = WatchMe_GetLaunchVolumeName();
  97.         if (myVolName != NULL) {
  98.             strcat(myName, myVolName);
  99.             strcat(myName, myTail);
  100.         }
  101.         
  102.         c2pstr(myName);
  103.         
  104.         // open the WatchMe movie
  105. #if TARGET_OS_MAC
  106.         MacSetCursor(*MacGetCursor(watchCursor));
  107. #endif
  108.         
  109.         FSMakeFSSpec(0, 0, (ConstStr255Param)myName, &myFSSpec);
  110.         DoCreateMovieWindow(NULL, &myFSSpec);
  111.         
  112. #if TARGET_OS_MAC
  113.         InitCursor();
  114. #endif
  115.  
  116.         if (myVolName != NULL)
  117.             free(myVolName);
  118.             
  119.     }    // end of kInitAppPhase_AfterCreateFrameWindow
  120.     
  121. }
  122.  
  123.  
  124. //////////
  125. //
  126. // StopApplication
  127. // Do any application-specific shut-down.
  128. //
  129. // The theStopPhase parameter determines which "phase" of application shut-down is executed,
  130. // *before* any open movie windows are destroyed or *after*.
  131. //
  132. //////////
  133.  
  134. void StopApplication (UInt32 theStopPhase)
  135. {
  136.     // do any shut-down activities that should occur after the movie windows are destroyed
  137.     if (theStopPhase & kStopAppPhase_AfterDestroyWindows) {
  138.         
  139.     }
  140. }
  141.  
  142.  
  143. //////////
  144. //
  145. // DoIdle
  146. // Do any processing that can/should occur at idle time.
  147. //
  148. //////////
  149.  
  150. void DoIdle (WindowReference theWindow)
  151. {
  152.     WindowObject         myWindowObject = NULL;
  153.     GrafPtr             mySavedPort;
  154.     
  155.     GetPort(&mySavedPort);
  156.     MacSetPort(GetPortFromWindowReference(theWindow));
  157.     
  158.     myWindowObject = GetWindowObjectFromWindow(theWindow);
  159.     if (myWindowObject != NULL) {
  160.         MovieController        myMC = NULL;
  161.     
  162.         myMC = (**myWindowObject).fController;
  163.         if (myMC != NULL) {
  164.         
  165.             MCIdle(myMC);
  166.  
  167. #if TARGET_OS_MAC
  168.             // restore the cursor to the arrow
  169.             // if it's outside the front movie window or outside the window's visible region
  170.             if (theWindow == GetFrontMovieWindow()) {
  171.                 Rect    myRect;
  172.                 Point    myPoint;
  173.                 
  174.                 GetMouse(&myPoint);
  175.                 MCGetControllerBoundsRect(myMC, &myRect);
  176.                 if (!MacPtInRect(myPoint, &myRect) || !PtInRgn(myPoint, GetPortFromWindowReference(theWindow)->visRgn))
  177.                     MacSetCursor(&qd.arrow);
  178.             }
  179. #endif    // TARGET_OS_MAC
  180.         }
  181.     }
  182.     
  183.     MacSetPort(mySavedPort);
  184. }
  185.  
  186.  
  187. //////////
  188. //
  189. // DoUpdateWindow
  190. // Update the specified window.
  191. //
  192. //////////
  193.  
  194. void DoUpdateWindow (WindowReference theWindow, Rect *theRefreshArea)
  195. {
  196. #pragma unused(theRefreshArea)
  197.     GrafPtr             mySavedPort;
  198.     
  199.     GetPort(&mySavedPort);
  200.     MacSetPort(GetPortFromWindowReference(theWindow));
  201.     
  202.     BeginUpdate(GetPortFromWindowReference(theWindow));
  203.     
  204.     // draw the movie controller and its movie
  205.     MCDoAction(GetMCFromWindow(theWindow), mcActionDraw, theWindow);
  206.     
  207.     EndUpdate(GetPortFromWindowReference(theWindow));
  208.     MacSetPort(mySavedPort);
  209. }
  210.  
  211.  
  212. //////////
  213. //
  214. // HandleContentClick
  215. // Handle mouse button clicks in the specified window.
  216. //
  217. //////////
  218.  
  219. void HandleContentClick (WindowReference theWindow, EventRecord *theEvent)
  220. {
  221. #pragma unused(theWindow, theEvent)
  222. }
  223.  
  224.  
  225. //////////
  226. //
  227. // HandleApplicationKeyPress
  228. // Handle application-specific key presses.
  229. // Returns true if the key press was handled, false otherwise.
  230. //
  231. //////////
  232.  
  233. Boolean HandleApplicationKeyPress (char theCharCode)
  234. {
  235. #pragma unused(theCharCode)
  236.     return(true);
  237. }
  238.  
  239.  
  240. #if TARGET_OS_MAC
  241. //////////
  242. //
  243. // CreateMovieWindow
  244. // Create a window to display a movie in.
  245. //
  246. //////////
  247.  
  248. WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
  249. {
  250.     WindowRef            myWindow;
  251.     
  252.     myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
  253.     return(myWindow);
  254. }
  255. #endif
  256.  
  257.  
  258. //////////
  259. //
  260. // HandleApplicationMenu
  261. // Handle selections in the application's menus.
  262. //
  263. // The theMenuItem parameter is a UInt16 version of the Windows "menu item identifier". 
  264. // When called from Windows, theMenuItem is simply the menu item identifier passed to the window proc.
  265. // When called from MacOS, theMenuItem is constructed like this:
  266. //     *high-order 8 bits == the Macintosh menu ID (1 thru 256)
  267. //     *low-order 8 bits == the Macintosh menu item (sequential from 1 to ordinal of last menu item in menu)
  268. // In this way, we can simplify the menu-handling code. There are, however, some limitations,
  269. // mainly that the menu item identifiers on Windows must be derived from the Mac values. 
  270. //
  271. //////////
  272.  
  273. void HandleApplicationMenu (UInt16 theMenuItem)
  274. {
  275. #pragma unused(theMenuItem)
  276. }
  277.  
  278.  
  279. //////////
  280. //
  281. // AdjustApplicationMenus
  282. // Adjust state of items in the application's menus.
  283. //
  284. // Currently, the Mac application has only one app-specific menu ("Test"); you could change that.
  285. //
  286. //////////
  287.  
  288. void AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu)
  289. {
  290. #pragma unused(theWindow, theMenu)
  291. }
  292.  
  293.  
  294. //////////
  295. //
  296. // DoApplicationEventLoopAction
  297. // Perform any application-specific event loop actions.
  298. //
  299. // Return true to indicate that we've completely handled the event here, false otherwise.
  300. //
  301. //////////
  302.  
  303. Boolean DoApplicationEventLoopAction (EventRecord *theEvent)
  304. {
  305. #pragma unused(theEvent)
  306.     
  307.     return(false);            // no-op for now
  308. }
  309.  
  310.  
  311. //////////
  312. //
  313. // AddControllerFunctionality
  314. // Configure the movie controller.
  315. //
  316. //////////
  317.  
  318. void AddControllerFunctionality (MovieController theMC)
  319. {
  320.     long            myControllerFlags;
  321.     
  322.     // CLUT table use
  323.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  324.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  325.  
  326.     // enable keyboard event handling
  327.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  328.     
  329.     // disable drag support
  330.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  331.     
  332.     // disable controller bar
  333.     MCSetVisible(theMC, false);
  334. }
  335.  
  336.  
  337. //////////
  338. //
  339. // InitApplicationWindowObject
  340. // Do any application-specific initialization of the window object.
  341. //
  342. //////////
  343.  
  344. void InitApplicationWindowObject (WindowObject theWindowObject)
  345. {
  346. #pragma unused(theWindowObject)
  347. }
  348.  
  349.  
  350. //////////
  351. //
  352. // RemoveApplicationWindowObject
  353. // Do any application-specific clean-up of the window object.
  354. //
  355. //////////
  356.  
  357. void RemoveApplicationWindowObject (WindowObject theWindowObject)
  358. {
  359. #pragma unused(theWindowObject)
  360.     // DoDestroyMovieWindow in MacFramework.c or MovieWndProc in WinFramework.c
  361.     // releases the window object itself
  362. }
  363.  
  364.  
  365. //////////
  366. //
  367. // ApplicationMCActionFilterProc 
  368. // Intercept some mc actions for the movie controller.
  369. //
  370. // NOTE: The theRefCon parameter is a handle to a window object record.
  371. //
  372. //////////
  373.  
  374. PASCAL_RTN Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon)
  375. {
  376. #pragma unused(theMC)
  377.  
  378.     Boolean                isHandled = false;            // false => allow controller to process the action
  379.     WindowObject        myWindowObject = NULL;
  380.     
  381.     myWindowObject = (WindowObject)theRefCon;
  382.     if (myWindowObject == NULL)
  383.         return(isHandled);
  384.         
  385.     switch (theAction) {
  386.     
  387.         // handle window resizing
  388.         case mcActionControllerSizeChanged:
  389.             SizeWindowToMovie(myWindowObject);
  390.             break;
  391.  
  392.         // handle link-to-URL events
  393.         case mcActionLinkToURL:
  394.             // the movie controller knows how to handle absolute URLs but not relative ones,
  395.             // so we need to convert any relative URLs to absolute ones
  396.             WatchMe_ConvertRelativeToAbsoluteURL((Handle)theParams, theRefCon);
  397.             break;
  398.             
  399.         default:
  400.             break;
  401.             
  402.     }    // switch (theAction)
  403.     
  404.     return(isHandled);    
  405. }
  406.